package cn.juque.datapipeline.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.juque.common.base.BaseResponseVO;
import cn.juque.common.constants.MessageEnum;
import cn.juque.datapipeline.bo.statistics.MostUseTimeGroupBO;
import cn.juque.datapipeline.bo.statistics.TaskRunDistributeBO;
import cn.juque.datapipeline.bo.statistics.TotalStatisticsBO;
import cn.juque.datapipeline.service.IStatisticsService;
import cn.juque.datapipeline.vo.statistics.MostUseTimeGroupVO;
import cn.juque.datapipeline.vo.statistics.TaskRunDistributeVO;
import cn.juque.datapipeline.vo.statistics.TotalStatisticsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>StatisticsController</li>
 * </ul>
 * @date 2023-04-11 23:58:57
 **/
@Slf4j
@Controller
@RequestMapping("/dpp/statistics")
public class StatisticsController extends BaseController {

    @Resource
    private IStatisticsService statisticsService;

    /**
     * 数量统计
     *
     * @return BaseResponseVO
     */
    @GetMapping(value = "/totalCount")
    @ResponseBody
    public BaseResponseVO<TotalStatisticsVO> totalCount() {
        TotalStatisticsBO totalStatisticsBO = this.statisticsService.totalGroupCount();
        TotalStatisticsVO vo = new TotalStatisticsVO();
        BeanUtil.copyProperties(totalStatisticsBO, vo);
        return new BaseResponseVO<>(MessageEnum.OK, vo);
    }

    /**
     * 数量统计
     *
     * @return BaseResponseVO
     */
    @GetMapping(value = "/statisticsDistribute")
    @ResponseBody
    public BaseResponseVO<TaskRunDistributeVO> statisticsDistribute(String date) {
        TaskRunDistributeBO bo = this.statisticsService.statisticsDistribute(date);
        TaskRunDistributeVO vo = new TaskRunDistributeVO();
        BeanUtil.copyProperties(bo, vo);
        return new BaseResponseVO<>(MessageEnum.OK, vo);
    }

    /**
     * 最耗时统计
     *
     * @return BaseResponseVO
     */
    @GetMapping(value = "/statisticsMostUseTime")
    @ResponseBody
    public BaseResponseVO<MostUseTimeGroupVO> statisticsMostUseTime(String date) {
        MostUseTimeGroupBO bo = this.statisticsService.statisticsMostUseTime(date);
        MostUseTimeGroupVO vo = new MostUseTimeGroupVO();
        BeanUtil.copyProperties(bo, vo);
        return new BaseResponseVO<>(MessageEnum.OK, vo);
    }
}
